<template>
  <div class="detail-list">
    <div v-if="title" class="title text-gray-500">{{ title }}</div>
    <div class="item" v-for="(item, index) of list" :key="index">
      <div class="item-title border-b">
        <van-icon name="label-o" />
        {{ item.title }}<span v-if="item.price" class="ml-1 text-red-600">￥{{ item.price }}</span>
      </div>
      <div class="item-children" v-if="item.children">
        <!-- 递归组件：调用自身组件和name属性一致 -->
        <detail-list :list="item.children"></detail-list>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'DetailList',
  props: {
    title: String,
    list: Array,
  },
}
</script>

<style lang="scss" scoped>
.detail-list {
  .title {
    padding: 0.1rem;
    font-size: 0.14rem;
  }
  .item {
    .item-title {
      line-height: 0.4rem;
      font-size: 0.16rem;
      padding: 0 0.1rem;
      .van-icon {
        color: $green;
      }
    }
    .item-children {
      padding: 0 0.1rem;
    }
  }
}
</style>
